function socketPush(data) {
  // 切换图层
  vm.form = data;
  // 点位
  var point = new BMap.Point(data.longitude, data.latitude)
  // 创建事件图标
  var myIcon = new BMap.Icon("./Package/images/alarm.gif", new BMap.Size(50, 50));
  // 点位
  var marker = new BMap.Marker(point, { icon: myIcon });
  // 覆盖物标识
  marker.init = 'socketevent';
  marker.setZIndex(9999);
  vm.map.addOverlay(marker);

  // 事件标题
  let name = ''
  for (let [key, val] of Object.entries(vm.EventList)) {
    if (val.id == data.eType) {
      name = val.eventName
      break;
    }
  }

  var opts = {
    position: point,    // 指定文本标注所在的地理位置
    offset: new BMap.Size(-(name.length * 20 / 2), 25)    //设置文本偏移量
  }

  var label = new BMap.Label(name, opts);  // 创建文本标注对象
  label.init = "socketevent";

  label.setStyle({
    fontSize: '18px',
    color: 'black',
    border: "0",
    background: 'transparent'
  });

  vm.map.addOverlay(label)
//console.log(data)
  var content = `
        <div class="MonitoringStyEvent">
          <div class="MonitoringStyEvent-title">事件信息</div>
          <div class="MonitoringStyEvent-content">
            <div class="MonitoringStyEvent-text">
              <span>事件标题</span>: <p>${name ? name : ''}</p>
            </div>
            <div class="MonitoringStyEvent-text">
              <span>发生地</span>: <p>${data.address ? data.address : ''}</p>
            </div>
            <div class="MonitoringStyEvent-text">
              <span>道路方向</span>: <p>${data.direction ? data.direction : ''}</p>
            </div>
            <div class="MonitoringStyEvent-text">
              <span>来源</span>: <p>${data.source ? data.source : ''}</p>
            </div>
            <div class="MonitoringStyEvent-text">
              <span>时间</span>: <p>${data.eCreateTime ? data.eCreateTime : ''}</p>
            </div>
            <div class="MonitoringStyEvent-text">
              <span>详情</span>: <p>${data.details ? data.details : ''}</p>
            </div>
            <img class="MonitoringStyEvent-img" src="${urlimgadd(data.spareList)}" alt="暂无图片">
            <div class="EventDetails" onclick="EventDetailsadd()">
              详情
            </div>
          </div>
        </div >
        `
  addClickHandler(content, marker, 'monitoring') // 监控信息窗口

  // 资源信息函数调用
  Informationdisplay(data);

  // 画圆
  DrawRound(data);
  // 获取人员信息
  userlistadd(data);
	// 获取车辆信息
	carlistadd(data)
}

// 画圆函数
function DrawRound(data) {
  // 点位
  var point = new BMap.Point(data.longitude, data.latitude)
  // 切换图层
  vm.map.setZoom(14);
  // 地图移动
  vm.map.panTo(point, false);
  var circle = new BMap.Circle(point, Math.ceil(vm.Radius) * 1000, {
    fillOpacity: '0.1',
    fillColor: '#34E5FF',
    strokeStyle: 'dashed' // 线的颜色
  })

  circle.init = 'circle'
  vm.map.addOverlay(circle)
  circle.enableEditing(); //开启线编辑
  // 清除资源列表
  vm.resourcesList = [];
//console.log(circle);
//console.log(circle.getBounds());

  xian(data, circle);

  var timerId = null // null = false
  circle.addEventListener('lineupdate', function () {
    // 函数防抖
    if (timerId) {
      window.clearTimeout(timerId)
    }
    // 获取圆的半径
    vm.Radius = this.getRadius() / 1000;
    xian(data, circle);

    //重新执行
    timerId = setTimeout(() => {
      timerId = null

      if (vm.Basisindex == 0) {
        // 清除资源列表
        vm.resourcesList = [];
				
        // 清除覆盖物
        vm.clear('personnel');
        vm.clear('policestate');
        vm.clear('Medical');
        vm.clear('monitoring');
				vm.clear('vehiclestate');
        vm.clear('carnel');
        vm.clear('monitoring');
        // 监控类型
        if (vm.polymerizationempnasiscamera != null) {
          vm.polymerizationempnasiscamera.removeMarkers(vm.polymerizationempnasiscameraList)
        }
        if (vm.polymerizationMedical != null) {
          vm.polymerizationMedical.removeMarkers(vm.polymerizationMedicalList); // 清除医院聚合数据
        }
        if (vm.polymerizationUser != null) {
          vm.polymerizationUser.removeMarkers(vm.polymerizationUserList); // 清除人员点聚合信息
        }

        if (vm.polymerizationCar != null) {
          vm.polymerizationCar.removeMarkers(vm.polymerizationCarList); // 清除车辆聚合数据
        }
        // 资源信息函数调用
        Informationdisplay(data);
      }
    }, 500) //1秒后再执行
  })
}

function xian(data, circle) {
//	console.log(data, circle)
  vm.clear('polylineEvent');
  vm.clear('labelevent');

  // 中心店
  let arrlist = [];
  arrlist.push(new BMap.Point(data.longitude, data.latitude));

  let add = parseInt(circle.ha.length / 4) * 3;
  arrlist.push(new BMap.Point(circle.ha[add].lng, circle.ha[add].lat));

  var polyline = new BMap.Polyline(arrlist, { strokeWeight: 4, strokeColor: "#3385FF", strokeOpacity: .5 });   //创建折线
  polyline.init = 'polylineEvent';
  vm.map.addOverlay(polyline);   //增加折线

  // 位置
  var point = new BMap.Point(circle.ha[add].lng, circle.ha[add].lat);
  // 标签创建
  var name = `
   <div style='width: auto; height: 22px; padding: 2px 5px; line-height: 22px; text-align: center;border:6px'>
     ${vm.Radius.toFixed(2)}公里
   </div>
 `
  var Distance = String(vm.Radius.toFixed(2)).length * 10;
//console.log(Distance);
  var opts = {
    position: point,    // 指定文本标注所在的地理位置
    offset: new BMap.Size(-Distance * 1, -30)    //设置文本偏移量
  }

  let label = new BMap.Label(name, opts);  // 创建文本标注对象
  label.init = "labelevent"
  label.setStyle({
    color: "#000",       //文本颜色
    fontSize: "14px",
    lineHeight: "24px",
    fontFamily: "微软雅黑",
    border: "0",
    borderRadius: '6px'
  });
  label.setZIndex(999999999);
  vm.map.addOverlay(label);
}

// 资源信息函数
function Informationdisplay(data) {
  let radius = Math.ceil(vm.Radius) || 50;
//console.log(radius)
  // 监控
  if (vm.basisMonitoringState) {
    Resources(data, 'road_camera', radius); // 监控设备
  }

  // 医院
  if (vm.basisHospitalState) {
    Resources(data, 'social_resources', radius);
  }

  // 人员信息
  if (vm.basisPersonnelState) {
    userResources(data, radius);
  }
	//车辆
	if(vm.basisCarState){
		carResources(data, radius);
	}
}

// 获取资源信息
function Resources(data, Identity, radius) {
  $.ajax({
    type: 'POST',
    url: httpurl + `basicInfo/manager/category/getFacilitiesDataByMap/${Identity}`,
    data: JSON.stringify({
      long: data.longitude,
      lat: data.latitude,
      distance: radius
    }),
    dataType: 'json',
    contentType: "application/json",
    headers: {
      Authorization: localStorage.getItem('token')
    },
    success: function (data) {
      // console.log(data)
      if (data instanceof Array) {
        for (let [key, val] of Object.entries(data)) {
          if (Identity == 'social_resources') {
            val.img = './Package/images/ylzy.png'
            val.init = 'Medical'
          } else {
            val.img = './Package/images/tb/jk-c.png'
            val.init = 'monitoring'
          }
          vm.resourcesList.push(val);
        }

        switch (Identity) {
          case 'camera':
            monitoringList(data, 'road_camera'); // 监控设备
            break;
          case 'road_camera':
            monitoringList(data, 'road_camera'); // 道路监控
            break;
          case 'emphasis_camera':
            monitoringList(data, 'emphasis_camera'); // 重点监控
            break;
          case 'social_resources':
            SocialList(data); // 医疗资源
            break;
        }

        vm.resourcesList = vm.resourcesList.sort(compare('api_distance_km'))
      }
    },
    error: function (err) {
      // 失败的回调
      console.log(err)
    }
  })
}

// 获取人员信息列表
function userlistadd(data) {
  $.ajax({
    type: 'post',
    url: httpurl + 'event/personLocation/getPersonLocation',
    data: JSON.stringify({
      "lon": data.longitude,
      "lat": data.latitude
    }),
    dataType: 'json',
    contentType: "application/json",
    headers: {
      Authorization: localStorage.getItem('token')
    },
    success: function (data) {
      // 成功的回调
      // console.log(data)
      if (data.data.length != 0) {
        vm.userlistadd = data.data;
      }
    },
    error: function (err) {
      // 失败的回调
    }
  })
}

// 获取车辆信息列表
function carlistadd(data) {
  $.ajax({
    type: 'post',
    url: httpurl + 'vehicle/vehicleDevice/list',
    data: JSON.stringify({
      "lng": data.longitude,
      "lat": data.latitude
    }),
    dataType: 'json',
    contentType: "application/json",
    headers: {
      Authorization: localStorage.getItem('token')
    },
    success: function (data) {
      // 成功的回调
      // console.log(data)
      if (data.data.length != 0) {
        vm.caralllistadd = data.data;
      }
    },
    error: function (err) {
      // 失败的回调
    }
  })
}

// 根据经纬度获取附近人员的信息
function userResources(data, radius) {
  if (vm.Basisindex != 0) {
    return;
  }
  $.ajax({
    type: 'POST',
    url: httpurl + 'event/personLocation/getPersonLocationDistance',
    data: JSON.stringify({
      lon: parseFloat(data.longitude),
      lat: parseFloat(data.latitude),
      distance: radius
    }),
    dataType: 'json',
    contentType: "application/json",
    headers: {
      Authorization: localStorage.getItem('token')
    },
    success: function (data) {
      // 清除点聚合信息
      vm.polymerizationUserList = [];

      if (data.code == 200 && data.data.length != 0) {
        for (let [key, val] of Object.entries(data.data)) {
//        console.log(val)
          vm.resourcesList.push({
            name: val.person.name,
            api_distance_km: val.distance,
            lng: val.lng,
            lat: val.lat,
            img: './Package/images/tb/ry.png',
            init: 'personnel'
          })

          vm.resourcesList = vm.resourcesList.sort(compare('api_distance_km'))

          var point = new BMap.Point(val.lng, val.lat)
          // 创建小车图标
          var myIcon = new BMap.Icon("./Package/images/tb/ry.png", new BMap.Size(34, 34));
          // 点位
          var marker = new BMap.Marker(point, { icon: myIcon });
          // 覆盖物标识
          marker.init = 'personnel'
          // vm.map.addOverlay(marker)

          var content = `
          <div class="MonitoringSty monbacking">
            <div class="MonitoringSty-title">人员信息</div>
            <div class="MonitoringSty-video">
              <ul class="textShow">
                <li>
                  <p>姓名</p>:
                  <p>${val.person.name ? val.person.name : ''}</p>
                </li>
                <li>
                  <p>职位</p>:
                  <p>${val.person.position ? val.person.position : ''}</p>
                </li>
                <li>
                  <p>电话</p>:
                  <p>${val.person.phone ? val.person.phone : ''}</p>
                </li>
              </ul>
            </div >
            <div class ="userTaskAssigned" onclick="Assignedadd(${val.person.id})">
              指派任务
            </div>
          </div >
          `
          addClickHandler(content, marker, 'personnel') // 监控信息窗口

          // 标签创建
          var name = `
               <div style='width: auto; height: 22px; padding: 2px 5px; line-height: 22px; text-align: center;'>
                 ${val.person['name']}-${val.distance}KM
               </div>
              `
          var Distance = val.person['name'].length * 8
          var opts = {
            position: point,    // 指定文本标注所在的地理位置
            offset: new BMap.Size(-Distance, 20)    //设置文本偏移量
          }
          let label = new BMap.Label(name, opts);  // 创建文本标注对象
          label.init = "personnel"
          label.setStyle({
            color: "#000",       //文本颜色
            fontSize: "14px",
            lineHeight: "24px",
            fontFamily: "微软雅黑",
            border: "0",
            borderRadius: '4px'
          });
          vm.map.addOverlay(label);

          // 收集点聚合信息
          vm.polymerizationUserList.push(marker);
        }

        //最简单的用法，生成一个marker数组，然后调用markerClusterer类即可。
        vm.polymerizationUser = new BMapLib.MarkerClusterer(vm.map, {
          markers: vm.polymerizationUserList,
          styles: [{
            url: './Package/images/tb/ry.png',
            size: new BMap.Size(34, 34),
            color: 'pink',
            textSize: 20,
            textColor: 'red'
          }]
        });
        // 设置最大缩放级别
        vm.polymerizationUser.setMaxZoom(11);
      }
    },
    error: function (err) {
      // 失败的回调
      console.log(err)
    }
  })
}

// 根据经纬度获取附近车辆的信息
function carResources(data, radius) {
  if (vm.Basisindex != 0) {
    return;
  }
  $.ajax({
    type: 'POST',
    url: httpurl + 'vehicle/vehicleDevice/list',
    data: JSON.stringify({
      lng: parseFloat(data.longitude),
      lat: parseFloat(data.latitude),
      distance: radius
    }),
    dataType: 'json',
    contentType: "application/json",
    headers: {
      Authorization: localStorage.getItem('token')
    },
    success: function (data) {
      // 清除点聚合信息
      vm.polymerizationCarList = [];

      if (data.code == 200 && data.data.length != 0) {
        for (let [key, val] of Object.entries(data.data)) {
//        console.log(val)
					if(val.online == 1){
						vm.resourcesList.push({
							name: val.vehiIdno,
							api_distance_km: val.distance,
							lng: val.lng,
							lat: val.lat,
							img: './Package/images/tb/caricon.png',
							init: 'carnel'
						})

						vm.resourcesList = vm.resourcesList.sort(compare('api_distance_km'))

						var point = new BMap.Point(val.lng, val.lat)
						// 创建小车图标
						var myIcon = new BMap.Icon("./Package/images/tb/caricon.png", new BMap.Size(34, 34));
						// 点位
						var marker = new BMap.Marker(point, { icon: myIcon });
						// 覆盖物标识
						marker.init = 'carnel'
						// vm.map.addOverlay(marker)

						var content = `
						<div class="MonitoringSty monbacking">
							<div class="MonitoringSty-title">车辆信息</div>
							<div class="MonitoringSty-video">
								<ul class="textShow">
									<li>
										<p>车牌号</p>:
										<p>${val.vehiIdno ? val.vehiIdno : ''}</p>
									</li>
									<li>
										<p>位置</p>:
										<p>${val.pos ? val.pos : ''}</p>
									</li>
								</ul>
							</div >
							<div class ="userTaskAssigned" onclick="Assignedadd(${val.vehiIdno})">
								指派任务
							</div>
						</div >
						`
						addClickHandler(content, marker, 'carnel') // 监控信息窗口

						// 标签创建
						var name = `
								 <div style='width: auto; height: 22px; padding: 2px 5px; line-height: 22px; text-align: center;'>
									 ${val['vehiIdno']}-${val.distance}KM
								 </div>
								`
						var Distance = val['vehiIdno'].length * 8
						var opts = {
							position: point,    // 指定文本标注所在的地理位置
							offset: new BMap.Size(-Distance, 20)    //设置文本偏移量
						}
						let label = new BMap.Label(name, opts);  // 创建文本标注对象
						label.init = "carnel"
						label.setStyle({
							color: "#000",       //文本颜色
							fontSize: "14px",
							lineHeight: "24px",
							fontFamily: "微软雅黑",
							border: "0",
							borderRadius: '4px'
						});
						vm.map.addOverlay(label);

						// 收集点聚合信息
						vm.polymerizationCarList.push(marker);
					}
				}
        //最简单的用法，生成一个marker数组，然后调用markerClusterer类即可。
        vm.polymerizationCar = new BMapLib.MarkerClusterer(vm.map, {
          markers: vm.polymerizationCarList,
          styles: [{
            url: './Package/images/tb/caricon.png',
            size: new BMap.Size(34, 34),
            color: 'pink',
            textSize: 20,
            textColor: 'red'
          }]
        });
        // 设置最大缩放级别
        vm.polymerizationCar.setMaxZoom(11);
      }
    },
    error: function (err) {
      // 失败的回调
      console.log(err)
    }
  })
}
// 根据经纬度获取附近人员信息
function userlistadddata(data, radius) {
  $.ajax({
    type: 'POST',
    url: httpurl + 'event/personLocation/getPersonLocationDistance',
    data: JSON.stringify({
      lon: parseFloat(data.longitude),
      lat: parseFloat(data.latitude),
      distance: radius
    }),
    dataType: 'json',
    contentType: "application/json",
    headers: {
      Authorization: localStorage.getItem('token')
    },
    success: function (data) {
      // console.log(data)
      vm.userlistadd = data.data
    }
  })
}

// 根据经纬度获取附近车辆信息
function carlistadddata(data, radius) {
  $.ajax({
    type: 'POST',
    url: httpurl + 'vehicle/vehicleDevice/list',
    data: JSON.stringify({
      lng: parseFloat(data.longitude),
      lat: parseFloat(data.latitude),
      distance: radius
    }),
    dataType: 'json',
    contentType: "application/json",
    headers: {
      Authorization: localStorage.getItem('token')
    },
    success: function (data) {
      // console.log(data)
      vm.carlistadd = data.data
    }
  })
}

// 排序
function compare(name) {
  return function (a, b) {
    var value1 = a[name];
    var value2 = b[name];
    return value1 - value2;
  }
}

// 人员任务指派
function Assignedadd(id) {
//console.log(id)

  vm.userlistaddstate.push(id);
  vm.Taskcontenttow = !vm.Taskcontenttow;
  vm.Taskcontenton = true;

//console.log(vm.resourcesList);
}

function EventDetailsadd() {
  // 显示事件详情
  vm.eventstate = true;
  vm.eventstatemap = false;

  // 事件详情赋值
  vm.form = vm.Earlywarning
}

function urlimgadd(data) {
// console.log(data,99999999);

  if (data != null && data.length > 0 && data[0] != '') {
    return httpimgtow + data[0]
  }else{
		return './Package/images/tb/person.jpg'
	}
}